package com.p2p.front.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;




public class ResourceBundleUtils {
	private final static Logger	log	= LoggerFactory.getLogger(ResourceBundleUtils.class);
	public static String getValue(String baseName,String key){
		ResourceBundle resourceBundle = getResourceBundle(baseName);
		return getValue(resourceBundle, key);
	}
	
	public static String getValue(ResourceBundle resourceBundle,String key){
		if (!resourceBundle.containsKey(key)){
			log.warn("resourceBundle don't containsKey:{}", key);
		}else{
			try{
				String value = resourceBundle.getString(key);
				if (value == null){
					log.warn("resourceBundle has the key:{},but value is null/empty", key);
				}
				return value;
			}catch (Exception e){
				log.error(e.getMessage());
			}
		}
		return null;
	}
	
	/**
	 * 获得ResourceBundle
	 * 
	 * @param baseName
	 * @return
	 */
	public static ResourceBundle getResourceBundle(String baseName){
		// Locale enLoc = new Locale("en", "US"); // 表示美国地区
		ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault());
		return resourceBundle;
	}
}
